 
 <?php
if(!empty($_POST)){
	
	$id=$_POST['id'];
	$value=$_POST['values'.$id];
	if($value==1)
	include ("saveimage.php");
	else
	include ("deleteimage.php");
}

 
  if($_SESSION['Permit']==1)
 { 
   
	$sql =sprintf("SELECT * FROM tblhome_image");
		
 } 
 else
 
 { 
 echo "Bạn khong được Quyền vào đây";
 exit;
}

define("ROOT_PATH",str_replace("admin","",dirname($_SERVER['PHP_SELF'])));
   $kq=mysql_query($sql)or die(mysql_error()); 
?>
<script type="text/javascript" src="<?php echo ROOT_PATH."ckfinder/ckfinder.js"?>">
</script>
<div align="center" style="padding:10 10 10 10; border:1px black solid;">

  <script type="text/javascript">
  
function BrowseServer()
{

	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.basePath = '<?php echo str_replace("admin","",ROOT_PATH)."ckfinder/";?>' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	
	finder.selectActionFunction = function(fileUrl){
		
		document.getElementById( 'addim' ).value = fileUrl ;
		document.getElementById( 'addimage' ).src = fileUrl;
		
	}
	finder.popup() ;

	
}

  function BrowerServere(id)
{

	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	
	finder.basePath = '<?php echo str_replace("admin","",ROOT_PATH)."ckfinder/";?>' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	
	finder.selectActionFunction = function(fileUrl){
		
		document.getElementById( 'url'+id ).value = fileUrl ;
		document.getElementById( 'img'+id ).src = fileUrl;
		
	}
	finder.popup() ;

	
}


function press(id)
{

	document.getElementById( 'values'+id ).value = 1 ;
	
}
  </script>
  
        <table width="100%">
          <tr>
            <td colspan="5"  style="font-size:14pt; font-weight:bold"> Quản lý hình ảnh trang chủ</td>
          </tr>
          
          <tr style="height:30px; background:#008000; color:white;">
            <th> Hiện thị </th>
            <th> Tên hình ảnh</th>
            <th> Đường dẫn</th>
            <th> Hình ảnh</th>
            <th> Thực hiện</th>
          </tr>
          <?php
               
                while ($Image=mysql_fetch_assoc($kq))
                {
                    
            ?>
          <tr >
           <form name="" action="" method="post">
            <td  align="center"><input type="checkbox" name="disp<?php echo $Image["id"] ?>" value="1"<?php if($Image["show"]=="1")echo "checked='checked'"; ?> /></td>
            <td ><input type="text"   name="name<?php echo $Image["id"] ?>" value="<?php echo $Image["name"] ?>" /></td>
            <td ><input type="text" id="url<?php echo $Image["id"] ?>" name="url<?php echo $Image["id"] ?>" value="<?php echo $Image["link"] ?>" /></td>
            <td ><img style="cursor: pointer;" src="<?php echo $Image["link"] ?>" id="img<?php echo $Image["id"] ?>" alt="Chọn hình ảnh" title="Click để chọn ảnh" width="150" height="150" onclick="BrowerServere(<?php echo $Image["id"] ?>)" /></td>
            <td >
            <input type="hidden" name="id" value="<?php echo $Image["id"] ?>"/>
            <input type="submit" name="btnDelete"  value="Xóa" />
            <input type="hidden" id="values<?php echo $Image["id"] ?>" name="values<?php echo $Image["id"] ?>" value="0"/>
            <input type="submit" name="btnSave" value="Lưu" onclick="press(<?php echo $Image["id"] ?>)" /></td>
              </form>
          </tr>
          <?php 
		  } 
		  ?>
          <tr style="border: 1px solid #e7e7e7;" >
          <form name="addimage" action="Images/addimage.php" method="post">
            <td  align="center"><input type="checkbox" name="disp"  value="1"/></td>
            <td ><input type="text"  name="name" /></td>
            <td><input type="text" id="addim"  name="link" /></td>
            <td ><img  style="cursor: pointer;" src="" id="addimage" alt="Chọn hình ảnh" width="150"  onclick="BrowseServer()"/></td>
            <td><input type="submit" name="3"  value="Thêm"/></td>
         </form>
          </tr>
        </table>
   

</div>
